<?php
class LoginAction extends Action {
    public function index()
	{
        $this->display("Login");
    }

	Public function verify()
	{
		import('ORG.Util.Image');
		Image::buildImageVerify();
	}
	public function login()
	{
		$UserName = $_POST['UserName'];
		$Password = $_POST['Password'];

		$User = D("Users");
		$UserInfo = $User->where("UserName ='$UserName'")->find();
		if(!empty($UserInfo))
		{
			if($UserInfo['Password'] == $Password)
			{
				if($_POST['remember'] ==1)
				{
					cookie('UserName',$UserInfo['password'],array('expire'=>time()+3600*24*365,'prefix'=>'nova_'));
					cookie('Password',$UserInfo['username'],array('expire'=>time()+3600*24*365,'prefix'=>'nova_'));
				}
				session('UserID',$UserInfo['UserID']);
				session('UserName',$UserName);
				session('Role',$UserInfo['Role']);
				if($UserInfo['Role']== "管理员"){
					$this->success('登陆成功！',"__APP__/TableView/index");
				}
				else{
					$this->success('登陆成功！',"__APP__/Index/index");
				}
				
			}
			else
			{
				$this->error('密码出错，请重新输入！', "__APP__/Login/index");
			}
		}
		else{
			$this->error('用户名不存在！', "__APP__/Login/index");
		}
	}
	public function logout()
	{
		session('[destroy]');
		/*if(!empty($_COOKIE['nova_username']) || !empty($_COOKIE['nova_password'])){  
			cookie(null,'nova_');
		}*/
		$this->success('退出成功！', "__APP__/Login/index");
	}
}
